package top.cluski.feieprint.api.teable.entity;


import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.experimental.Accessors;
import top.cluski.feieprint.api.teable.entity.Filter.Operator;

import java.time.ZonedDateTime;

import static cn.hutool.core.date.DatePattern.UTC_PATTERN;

@Data
@Accessors(chain = true)
public class FilterItem<T> {
    String fieldId;
    Operator operator;
    T value;

    public static <T> FilterItem<T> create() {
        return new FilterItem<>();
    }

    @Data
    @Accessors(chain = true)
    public static class TimeFilterValue {
        TimeFilterMode mode;
        @JsonFormat(pattern = UTC_PATTERN)
        ZonedDateTime exactDate;
        String timeZone = "Asia/Shanghai";

        public static TimeFilterValue create() {
            return new TimeFilterValue();
        }

        public static TimeFilterValue extraDate(ZonedDateTime exactDate) {
            return create().setMode(TimeFilterMode.extraDate).setExactDate(exactDate);
        }

        public static TimeFilterValue yesterday() {
            return create().setMode(TimeFilterMode.yesterday);
        }

        public static TimeFilterValue today() {
            return create().setMode(TimeFilterMode.today);
        }

        public static TimeFilterValue tomorrow() {
            return create().setMode(TimeFilterMode.tomorrow);
        }

        public static TimeFilterValue currentWeek() {
            return create().setMode(TimeFilterMode.currentWeek);
        }

        public static TimeFilterValue lastWeek() {
            return create().setMode(TimeFilterMode.lastWeek);
        }

        public static TimeFilterValue nextWeekPeriod() {
            return create().setMode(TimeFilterMode.nextWeekPeriod);
        }

        public static TimeFilterValue currentMonth() {
            return create().setMode(TimeFilterMode.currentMonth);
        }
    }

    public enum TimeFilterMode {
        extraDate,
        yesterday,
        today,
        tomorrow,
        currentWeek,
        lastWeek,
        nextWeekPeriod,
        currentMonth
        ;
    }
}